/**  
 * ----------------------------------------------------------
 * This software is for educational purposes only.
 * The base of this software was created by IntelliJ IDEA.
 * Additions to the base have been made by the Hood College
 * Computer Science Department, Graduate Group 1.
 * ----------------------------------------------------------
 *
 * History:
 * @version: $Revision: 154 $
 * @date: $Date: 2010-11-29 04:11:04 +0000 (Mon, 29 Nov 2010) $
 * @author: $Author: jwoozeR $
 */

package simulator.Packets;

import logger.FileLogger;
import simulator.Node;
import simulator.noderelated.tasks.RREQ_Received;

public class RREQPacket extends Packet {
	private int SourceSeq_no;
	public boolean J, R, D, G, U;
	private int RREQ_ID;

	public int getRREQ_ID() {
		return RREQ_ID;
	}

	public void setRREQ_ID(int RREQ_ID) {
		this.RREQ_ID = RREQ_ID;
	}

	public RREQPacket() {
		this.type = 1;
	}

	public int getSourceSeq_no() {
		return SourceSeq_no;
	}

	public void setSourceSeq_no(int destSeq_no) {
		this.SourceSeq_no = destSeq_no;
	}

	public Packet copy_packet() {
		RREQPacket copy_of = new RREQPacket();
		this.copy_parentvalue(copy_of);
		copy_of.SourceSeq_no = ((RREQPacket) this).SourceSeq_no;
		copy_of.J = J;
		copy_of.R = R;
		copy_of.D = D;
		copy_of.G = G;
		copy_of.U = U;
		copy_of.RREQ_ID = RREQ_ID;
		return copy_of;
	}

	public void receive(Node receiver, Node prev_hop) {

		receiver.add_Route(receiver.generateRouteFromRREQtoprevHop(this,
				prev_hop));
		if (receiver.checkAndUpdateBroadCastTable(this.source, this)) {
			// checks if this packet has not broadcasted and the source node is
			// not this
			new RREQ_Received("Message received from "
					+ receiver.getIP().toString(), receiver, this, prev_hop);
			FileLogger.write("Message received from "
					+ receiver.getIP().toString(), FileLogger.MSG_TYPE_INFO);
		}
	}

	public String toString() {
		return "RREQ X " + super.toString();
	}

}
